const { User } = require("../../models");
const { success, failure } = require("../../utils/responses");
const userService = require("../../services/charts/userService");
/**
 * 用户性别统计
 * @param req
 * @param res
 * @returns {Promise<void>}
 */

exports.userChartSex = async (req, res) => {
  try {
    const male = await User.count({ where: { sex: 0 } });
    const female = await User.count({ where: { sex: 1 } });
    const unknown = await User.count({ where: { sex: 2 } });
    const data = [
      { value: male, name: "男性" },
      { value: female, name: "女性" },
      { value: unknown, name: "其他" },
    ];
    // 返回
    success(res, "用户性别统计", { data });
  } catch (error) {
    failure(res, error);
  }
};

/**
 * 用户数量统计 -年月
 * GTE  /charts/count/
 */
exports.userChartCount = async (req, res) => {
  try {
    // servers
    const data = userService.testService(req, res);
    success(res, "用户性别统计", { data });
  } catch (error) {
    failure(res, error);
  }
};
